- install Xdebug for php
- Xdebug deepens debugging PHP apps and websites to a level you can’t receive from the manual process of using code level
var_dump()
.
Setup
To install Xdebug for PHP7 on Ubuntu you will need to do so manually. Ubuntu 15 and lower will not come with a package for PHP7 or its xDebug counterpart.
First, be sure you are using PHP 7 already by checking your version.
php -v
Should give you something like:
PHP 7.0.0-2+deb.sury.org~trusty+1 (cli) ( NTS ) Copyright (c) 1997-2015 The PHP Group ...
In my case I’m using the Larval Homestead PHP 7 branch with Vagrant and the VirtualBox provider. So, I have PHP 7 already installed and working with Nginx.
Get your php.ini
Next output your
php.ini
information into a file or place you can get to the information from. I like to save mine to a file calledphp-info.txt
.sudo php -i > ~/php-info.txt
Use the Xdebug Wizard
Send the text file information into the wizard at Xdebug Wizard. Then follow the instructions the wizard supplies.
Also, if you are using OSX you may need to run
brew install autoconf
.Example
The instructions should look something like:
- Download
xdebug-2.4.0.tgz
(I like to usewget -O ~/downlaods/xdebug-2.4.0.tgz http://xdebug.org/files/xdebug-2.4.0.tgz
on Ubuntu) - Unpack the downloaded file with
tar -xvzf xdebug-2.4.0.tgz
- Run:
cd xdebug-2.4.0
- Run:
phpize
(See the Xdebug FAQ if you don’t have phpize.)
As part of its output it should be like:
Configuring for: ... Zend Module Api No: 20151012 Zend Extension Api No: 320151012
If it does not, you are using the wrong phpize. Please follow this FAQ entry and skip the next step.
- Run:
./configure
- Run:
make
- Run:
cp modules/xdebug.so /usr/lib/php/20151012
- Edit
/etc/php/7.0/cli/php.ini
andfpm
and add the line
zend_extension = /usr/lib/php/20151012/xdebug.so
Enable Remote Xdebug
To use Xdebug remote debugging on a host computer you need to enable remote debugging on the guest server. In my case the guest is the Vagrant Homestead VM.
In the guest
php.ini
file add:zend_extension = /usr/lib/php/20151012/xdebug.so xdebug.remote_enable = 1 #xdebug.remote_connect_back=1 xdebug.remote_port = 9000 xdebug.scream=0 xdebug.show_local_vars=1 xdebug.idekey=PHPSTORM xdebug.remote_autostart = 1 xdebug.remote_host=192.168.7.3
Since I use PhpStorm for Debugging I set my Xdebug key to
PHPSTORM
. In the browser the Xdebug and PhpStorm will look for a cookie calledXDEBUG_SESSION
with the valuePHPSTORM
. To set this cookie I use the Chrome Browser extension Xdebug helper. - Download
2. configuration for phpstorm
PHP Storm lovers
With PhpStorm, it is even easier to set up everything since it has native Xdebug integration.
1. Open Magento 2 project
- Open up a project
- Go to Preferences
- Search for servers in the popup’s upper left search field
- Click on Servers under PHP, as shown on the screenshot above
2. Set it up
When you are done with the previous step, you will get a window on the right, which will look like this (with values already set):
I uncheck map project *****
So, this is step by step what you need to do: